package com.haoshuang.zhouzhoubang.ui.page.order

import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.FaceParamsBean
import com.haoshuang.zhouzhoubang.model.bean.HomeDataBean
import com.haoshuang.zhouzhoubang.model.bean.NumBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.ResponseBean
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData


class OrderViewModel : BaseViewModel() {

    /**
     * 获取订单数量
     */
    val getMasterOrderNumData = StatefulMutableLiveData<NumBean>()
    fun getMasterOrderNum() = netRequest {
        start { getMasterOrderNumData.value = StateData.Loading }
        request { ApiRepo.getMasterOrderNum() }
        success { getMasterOrderNumData.value = StateData.Success(it.data) }
        error { code, msg ->
            getMasterOrderNumData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 获取首页数据
     */
    val getHomeDataData = StatefulMutableLiveData<ResponseBean<HomeDataBean>>()
    fun getHomeData() = netRequest {
        start { getHomeDataData.value = StateData.Loading }
        request { ApiRepo.getHomeData() }
        success { getHomeDataData.value = StateData.Success(it) }
        error { code, msg ->
            getHomeDataData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 获取人脸识别参数信息
     */
    val getFaceParamsData = StatefulMutableLiveData<ResponseBean<FaceParamsBean>>()
    fun getFaceParams(certName: String?, certNo: String?, metaInfo: String?) = netRequest {
        start { getFaceParamsData.value = StateData.Loading }
        request { ApiRepo.getFaceParam(certName, certNo, metaInfo) }
        success { getFaceParamsData.value = StateData.Success(it) }
        error { code, msg ->
            getFaceParamsData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 人脸识别回调
     */
    val faceRecognitionCallbackData = StatefulMutableLiveData<ResponseBean<Any>>()
    fun faceRecognitionCallback() = netRequest {
        start { faceRecognitionCallbackData.value = StateData.Loading }
        request { ApiRepo.faceRecognitionCallback()  }
        success { faceRecognitionCallbackData.value = StateData.Success(it) }
        error { code, msg ->
            faceRecognitionCallbackData.value = StateData.Error(code, msg)
        }
    }

    /**
     *  验证门店是否上传了营业执照
     */
    val checkStoreLicenseData = StatefulMutableLiveData<ResponseBean<Any>>()
    fun checkStoreLicense() = netRequest {
        start { checkStoreLicenseData.value = StateData.Loading }
        request { ApiRepo.checkStoreLicense() }
        success { checkStoreLicenseData.value = StateData.Success(it) }
        error { code, msg ->
            checkStoreLicenseData.value = StateData.Error(code, msg)
        }
    }

}